<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$setting=$this->plugin_setting('setting');
set_html('title','我的二维码');
$member=model('core/member')->basic($_SESSION['uid']);
if($_RQ['op']=='main'){
	if($setting['closed_qrcode']){
		exi('没有开启推广二维码','error','/fenxiao.index/');
	}
	$jy_poster = $this->plugin_exists('jy_poster');
	if($jy_poster){
		$poster=pdo_get('jy_poster_poster',array('isdefault'=>1,'type'=>4,'uniacid'=>$_SESSION['uniacid']));
		if($poster['id']){
			exi('','','jy_poster/build//posterid='.$poster['id']);
		}
	}
	$setting['tcommission']=$setting['tcommission']?$setting['tcommission']:'佣金';
	if($setting['become_child']==1){
		$setting['t1']='如果您的好友下单，';
	}else{
		$setting['t1']='如果您的好友下单并付款，';
	}
	$setting['torder']=$setting['torder']?$setting['torder']:'分佣订单';
	$setting['tmydown']=$setting['tmydown']?$setting['tmydown']:'我的下线';
	$setting['twithdraw']=$setting['twithdraw']?$setting['twithdraw']:'提现';	
	$return['setting']=$setting;
	$share_link=$setting['share_link']?:'jy_newcar/index/';
	if(substr($share_link,-1)=='//'){
	}elseif(substr($share_link,-1)=='/'){
		$share_link=$share_link.'/';
	}else{
		$share_link=$share_link.'&';
	}
	$url=custom_url($share_link.'fromuser='.$_SESSION['uid'],true);
	$return['qrcode']=cfc('tools')->createqrcode($url,'250',true);
	$return['qrcode']=tomedia($return['qrcode']);
	if($_SESSION['wxapp_id']){
		$image='oss/'.$_SESSION['uniacid'].'/images/jy_newcar/wxappid'.$_SESSION['uid'].'.jpg';
		$isadd=cfc('files')->source_check($image);
		if(!$isadd){
			$url=wxapp_links($share_link.'fromuser='.$_SESSION['uid']);
			$wxapp=pdo_get('core_account_wxapp',array('id'=>$_SESSION['wxapp_id'],'uniacid'=>$_SESSION['uniacid']));
			if($_SESSION['fromh5wxapp']){
				$url=$share_link.'fromuser='.$_SESSION['uid'];
				$url='/pages/index/index?url='.urlencode($url);
			}
			$res=model('core/wxapp')->appcode($url,$wxapp['appid'],$wxapp['appsecret'],200);
			$path='oss/'.$_SESSION['uniacid'].'/images/jy_newcar';
			if(!file_exists(ROOT_AT.$path)){
				mkdir(ROOT_AT.$path,0700, true);
			}
			cfc('files')->source_save($res,'nochoose','png','二维码',$image,'',$url);
		}
		$return['qrcode']=$return['appcode']=$image;
	}
	$return['url']=$url;
	$return['sharedata']=array(
			'title'=>$member['nickname']?:'快来参加哦！',
			'desc'=>$setting['share_desc']?:'快来参加哦',
			'link'=>custom_url('jy_newcar/index//fromuser='.$_SESSION['uid'],true),
			'imgUrl'=>tomedia($member['avatar']),
	);
	exi($return);
}

?>